var debug = function(i) {window.console.log(i);};

(function() {

cpark = 
{
	req : null,
	
	responseReceived : function()
	{
		//window.console.log("responseReceived entered \(req.readyState="
		// + req.readyState + "\, req.status=" + req.status + "\)");

		if (cpark.req.readyState == 4) { 		// only if req shows "loaded"
			if (cpark.req.status == 200) { 	// only if "OK"
				var elems = cpark.req.responseXML.getElementsByTagName("item");
				var i = 0;
				for (i = 0;  i < elems.length; i++) {
					//window.console.log(i + " : " + elems[i].firstChild.firstChild.nodeValue);
					//window.console.log(i + " : " + elems[i].childNodes[2].firstChild.nodeValue);

					var ul = document.getElementById("naverNews");
					var newel = document.createElement("li");
					var newa = document.createElement("a");
					newa.setAttribute("href", elems[i].childNodes[2].firstChild.nodeValue);
					var newtext = document.createTextNode(elems[i].firstChild.firstChild.nodeValue);
					newa.appendChild(newtext);
					newel.appendChild(newa);
					ul.appendChild(newel);
				}
			}
		}
	},

	getNaverNews : function()
	{
		debug("getNaverNews");
		
		cpark.req = new XMLHttpRequest();		
		
		var url = "http://openapi.naver.com/search?";
		url += "key=" + "c7008262093d9cce24c4da03b58057b4";
		url += "&target=" + "news";  
		url += "&query=" + "bonus";
		
		window.console.log(url);

		cpark.req.open("GET", url, true)
		cpark.req.onreadystatechange = cpark.responseReceived;
		cpark.req.send("");
	}
};

})();